# -*- coding: utf-8 -*-

# -------------------------------
# Author    : linlingwei
# Email     : 951035650@qq.com
# File Name : filepath_editor.py
# Date      : 2019/11/18 
# IDE       : PyCharm
# Version   : 1.0.1
# -------------------------------

import os

import maya.cmds as mc
import maya.mel as mel

from configs.constants.global_constant import *

import scripts.commonCmds as con
reload(con)
import scripts.deformerCmds as dc
reload(dc)
import editors.editor as editor
reload(editor)

class FilepathEditor(editor.Editor):
    def __init__(self):
        super(FilepathEditor,self).__init__()
        self.fp_layout = "fp_layout"
    def win(self):
        _win = self.selfWindow()
        mc.menuBarLayout(bgc=self.rgbConvert(118, 137, 143))
        mc.menu("File", )
        mc.menuItem()
        mc.setParent("..")
    
        inlayout = mc.columnLayout(adj=True)
        row = mc.rowLayout(nc=10)
        input_tf = "input_tf"
        mc.textField(input_tf,tx="//taikonet")
        mc.button("Refresh",c=lambda *args:self.btn_refresh(input_tf))
        mc.setParent("..")
        mc.separator()
        self.main_layout()

        # mc.text(self.text("ddddd"))
        self.copyright(inlayout)
        mc.setParent("..")
        mc.showWindow(_win)
        return

    def main_layout(self):
        
        column = mc.columnLayout(self.fp_layout,adj=True)
        
        mc.setParent("..")
    
    
        return
    def btn_refresh(self,input_tf):
        
        it = mc.textField(input_tf,q=True,tx=True)
        _nodes = mc.ls(typ="shadingDependNode")
        uf_dict = {}
        for i in _nodes:
            _uf = mc.listAttr(i, uf=1)
            if _uf:
                uf_dict[i] = _uf

        waring_node = []
        for _u in uf_dict:
            for _f in uf_dict[_u]:
                attr = _u + "." + _f
                try:
                    fp = mc.getAttr(attr)
                except:
                    pass
                # print fp
                if fp and it in fp:
                    # print attr
                    if _u not in waring_node:
                        waring_node.append(_u)
                        self.btn_(_u)
                        print _u
                    
        return
    def btn_(self,tag):
        row = mc.rowLayout(nc=10,p=self.fp_layout)
        mc.checkBox(l="")
        mc.button(l=tag, c=lambda *args: self.btn_cmd(tag), )
        mc.setParent("..")
        return
    def btn_cmd(self,tag):
        mc.select(tag)
        return
    

    
def showEditor():
    FilepathEditor().win()
if __name__ == '__main__':
    pass